Fix issue with transitive/recursive building of PIC libraries #25707
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This issue was introduces in #25522 when
-sRELOCATABLEwas removed from `get_base_cflags.This is a somewhat tricky to reproduce / understand issue with transitive library building:
User attempts to compile program using SDL2 + SDL2_GFX.
emccattempts to builds all needed libraries in reverse dependency order. And ends up with the follows sequence:libsdl2-pic
libsdl2_gfx-pic
emccbuilds libsdl2-picemccbuilds libsdl2_gfx-pic. The command that it constructs when building each source file looks likeemcc -fPIC gfx.c -sUSE_SDL=2. However because neither-sMAIN_MODULEnor-sRELOCATABLEwere specified thisemcccommand will not try to build the non-PIC version of libsdl2. At this point the compiler will crash with:AssertionError: attempt to lock the cache while a parent process is holding the lock (sysroot/lib/wasm32-emscripten/libSDL2.a)This issue is hard to reproduce because if libsdl2 is already built it will not trigger the issue.